﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Disk
{
    public partial class findcode : Form
    {
        public static login login = new login();
        public findcode()
        {
            InitializeComponent();
        }
        //返回登陆
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            login.Show();
            this.Hide();
        }
        //关闭窗体
        private void findcode_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
        //找回密码单击事件
        private void Rebutton_Click(object sender, EventArgs e)
        {
            string username;
            string oldpassword;
            string newpassword;
            string Secret;
            string answer;
            if (IdBox.Text != "")
            {
                if (PassBox.Text != "")
                {
                    if (RePassBox.Text != "")
                    {
                            if (QuestionBox.Text != "")
                            {
                                if (Answer.Text != "")
                                {
                                    username = IdBox.Text;
                                    oldpassword = PassBox.Text;
                                    newpassword = RePassBox.Text;
                                    Secret = QuestionBox.Text;
                                    answer = Answer.Text;
                                  bool aoteman = Upload.Retrieve(username, oldpassword, newpassword, Secret, answer);
                                if (aoteman==true)
                                {
                                    MessageBox.Show("找回密码,进入登录界面", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    //显示登录窗体，关闭找回密码窗体
                                    login.Show();
                                    this.Hide();
                                }
                                else
                                {
                                    MessageBox.Show("找回失败，错误可能：1、账号或密码错误。2、密保问题或密保答案错误", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                  
                                }
                                else if (Answer.Text == "")
                                {
                                Answer.Focus();
                                MessageBox.Show("请输入密保答案", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else if (QuestionBox.Text == "")
                            {
                            QuestionBox.Focus();
                            MessageBox.Show("请选择密保问题", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                    }
                    else if (RePassBox.Text == "")
                    {
                        RePassBox.Focus();
                        MessageBox.Show("请输入新密码", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (PassBox.Text == "")
                {
                    PassBox.Focus();
                    MessageBox.Show("请输入原始密码", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else if (IdBox.Text == "")
            {
                IdBox.Focus();
                MessageBox.Show("请输入账号", "找回提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        //加载事件
        private void findcode_Load(object sender, EventArgs e)
        {
            IdBox.Focus();
        }
        //图片更改
        private void IdBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }

        private void PassBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }

        private void RePassBox_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }

        private void QuestionBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili1;
        }

        private void Answer_TextChanged(object sender, EventArgs e)
        {
            this.pictureBox2.Image = Properties.Resources.bili3;
        }
    }
}
